//
//  ViewController.m
//  M-Saler
//
//  Created by Teresa on 2020/5/13.
//  Copyright © 2020 Teresa. All rights reserved.
//

#import "ViewController.h"
#import "MHMyCompanyRootController.h"
#import "MHTokenListController.h"
#import "MHMyClientListController.h"
#import "MHLoginController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *dateTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *userNameLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear: animated];
    [self.navigationController setNavigationBarHidden:YES];
    [self configDateTime];
    [self showUserName];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

-(void)configDateTime{
    NSDateFormatter  *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"M月d日 EEEE";
    formatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh-Hans"] ;
    NSString *strTemp = [formatter stringFromDate:[NSDate date]];
    self.dateTimeLabel.text = strTemp;
}

-(void)showUserName{
    NSString *name = [MHUserModel userModel].name;
    if (name.length > 0) {
        self.userNameLabel.text = [NSString stringWithFormat:@"，%@",name];
    }else{
        self.userNameLabel.text = nil;
    }
}
#pragma mark - Actions

- (IBAction)pushToMyCompany:(id)sender {
    if([[MHUserModel userModel]didLogin]){
        MHMyCompanyRootController *newVC = [MHMyCompanyRootController new];
        [self.navigationController pushViewController:newVC animated:YES];
    }else{
        [self goLogin];
    }
}
- (IBAction)pushToTokenList:(id)sender {
    if([[MHUserModel userModel]didLogin]){
        MHTokenListController *newVC = [MHTokenListController new];
        [self.navigationController pushViewController:newVC animated:YES];
    }else{
        [self goLogin];
    }
}
- (IBAction)pushToCustomList:(id)sender {
    if([[MHUserModel userModel]didLogin]){
        MHMyClientListController *newVC = [[MHMyClientListController alloc]init];
        [self.navigationController pushViewController:newVC animated:YES];
        
    }else{
        [self goLogin];
    }
}

- (IBAction)pushToOrderList:(id)sender {
    if([[MHUserModel userModel]didLogin]){
        self.tabBarController.selectedIndex = 1;
    }else{
        [self goLogin];
    }
}

-(void)goLogin{
    MHLoginController *newVC = [MHLoginController new];
    newVC.modalPresentationStyle = UIModalPresentationFullScreen;
    [self.navigationController presentViewController:newVC animated:YES completion:nil];
}


@end
